﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using JiuZuWuFu.Models;
using Microsoft.AspNetCore.Mvc;

namespace JiuZuWuFu.Controllers
{
    public class MergeController : Controller
    {
        public IActionResult Index(int thisUserId, int byUserId)
        {
            JackGenealogyJiuZuWuFuContext zuWuFuContext = new JackGenealogyJiuZuWuFuContext();
            var inviteUser = zuWuFuContext.UserTb.Find(thisUserId);
            var byInviteUser = zuWuFuContext.UserTb.Find(byUserId);
            //获取邀请人
            var inviteUsers = (from userTb in zuWuFuContext.UserTb
                               join relationTb in zuWuFuContext.RelationTb.Where(x => x.PedigreeId == 5)
                               on userTb.UserId equals relationTb.UserId
                               where relationTb.PedigreeId == 5
                               select new UserList
                               {
                                   UserId = userTb.UserId,
                                   UserName = userTb.UserName,
                                   ParentId = userTb.ParentId,
                                   Sex = userTb.Sex
                               }).ToList();

            //获取被邀请人
            var byInviteUsers = (from userTb in zuWuFuContext.UserTb
                                 join relationTb in zuWuFuContext.RelationTb.Where(x => x.PedigreeId == 6)
                                 on userTb.UserId equals relationTb.UserId
                                 where relationTb.PedigreeId == 6
                                 select new UserList
                                 {
                                     UserId = userTb.UserId,
                                     UserName = userTb.UserName,
                                     ParentId = userTb.ParentId,
                                     Sex = userTb.Sex
                                 }).ToList();
            return View();
        }
    }
}